/*
* This file is a part of the open-eBackup project.
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
* If a copy of the MPL was not distributed with this file, You can obtain one at
* http://mozilla.org/MPL/2.0/.
*
* Copyright (c) [2024] Huawei Technologies Co.,Ltd.
*
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
*/
#ifndef NAS_UTILITIES_CERMGR_H
#define NAS_UTILITIES_CERMGR_H

#include <iostream>
#include "ApplicationProtectBaseDataType_types.h"
#include "ApplicationProtectPlugin_types.h"
#include "ApplicationProtectFramework_types.h"
#include "constant/PluginServiceCommon.h"

class CertMgr {
public:
    CertMgr() {}
    ~CertMgr();
    std::string GetCertPath() const;
    std::string GetCrlPath() const;
    bool InitInfo(const AppProtect::ApplicationEnvironment& protectEnv, const std::string& jobId);
    bool IsVerify() const;
    bool IncludeRevocationList() const;
    /*
    * 若m_authExt内需要包含certification和revocationlist字段
    * 将证书信息和吊销列表信息落盘保存
    */
    bool FlushCertificationToDisk() const;
    bool FlushRevocationListToDisk() const;

    /*
    * 删除CA证书和吊销列表临时文件，
    * 通过直接删除保存证书相关信息的rootPath实现
    */
    bool RemoveCertAndRevocationListFromDisk() const;

private:
    std::string m_rootPath;
    std::string m_certPath;
    std::string m_crlPath;
    bool m_verifyStatus {false};
    AuthExtendInfo m_authExt;
    ProtectEnvExtendInfo m_protectEnvExtendInfo;
    bool SaveFile(const std::string &filePath, const std::string &content, int cycleNums = 3) const;
};

#endif  // #define NAS_UTILITIES_CERMGR_H